import { fileURLToPath, URL } from "url";

import { defineConfig } from "vite";
import { createHtmlPlugin } from "vite-plugin-html";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import config from "./src/config";
const { title } = config;

// https://vitejs.dev/config/
export default defineConfig(() => {
  return {
    plugins: [
      vue(),
      vueJsx(),
      Components({
        resolvers: [NaiveUiResolver()],
      }),
      createHtmlPlugin({
        inject: {
          data: {
            title: title,
          },
        },
      }),
    ],
    // 反向代理
    // server: {
    //   host: "0.0.0.0", //服务器ip地址
    //   port: 5566, //本地端口
    //   fs: {
    //     strict: false, //  支持引用除入口目录的文件
    //   },
    //   open: true, // 是否自动在浏览器打开
    //   proxy: {
    //     "/api": {
    //       target: "",
    //       changeOrigin: true,
    //       rewrite: (path) => path.replace(/^\/api/, ""),
    //     },
    //   },
    // },
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    define: {
      "process.env": {
        BASE_API: "http://localhost:8011/api",
      },
    },
  };
});
